package com.heakey.common.util;

import cn.hutool.core.util.StrUtil;
import com.heakey.common.exception.BusinessException;
import com.heakey.common.iface.IErrorCode;

/**
 * @Description 业务断言
 * @Author Bing
 * @Date 2024/10/10 14:07
 */
public class AssertBusUtils {

    public static void notNull(Object object, IErrorCode errorCode){
        if (object == null) {
            BusinessException.throwBusException(errorCode.getCode(), errorCode.getMessage());
        }
    }

    public static void isNull(Object object, IErrorCode errorCode){
        if (object != null) {
            BusinessException.throwBusException(errorCode.getCode(), errorCode.getMessage());
        }
    }

    public static void notBlank(String str, IErrorCode errorCode){
        if (StrUtil.isBlank(str)) {
            BusinessException.throwBusException(errorCode.getCode(), errorCode.getMessage());
        }
    }

    public static void isBlank(String str, IErrorCode errorCode){
        if (StrUtil.isNotBlank(str)) {
            BusinessException.throwBusException(errorCode.getCode(), errorCode.getMessage());
        }
    }

    public static void isTrue(boolean flag, IErrorCode errorCode){
        if (!flag) {
            BusinessException.throwBusException(errorCode.getCode(), errorCode.getMessage());
        }
    }

    public static void isFalse(boolean flag, IErrorCode errorCode){
        if (flag) {
            BusinessException.throwBusException(errorCode.getCode(), errorCode.getMessage());
        }
    }

}